<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="LAFDC.DataAccess" %>
<%@ Import Namespace="LAFDC.Logging" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Adh&eacute;rent: Consultation</title>
    <link type="text/css" rel="stylesheet" href="skins/style.css"/>
    <script src="javascript/lafdc-helper.js" type="text/javascript"></script>
    <script src="javascript/lafdc-ajax.js" type="text/javascript"></script>
    <script src="javascript/lafdc-routage.js" type="text/javascript"></script>
	<script language="c#" runat="server">
		private string adh_previd = string.Empty;
		public string js_previd_var = string.Empty;
		private static readonly string source = "AdherentConsultation.aspx";

		protected void Page_Load(object sender, EventArgs e) {
			if (this.Request.Params.Count > 0) {
				adh_previd= this.Request.QueryString.Get("adh");
				txtPREV_ID.Text = adh_previd;

				if ((adh_previd == null) || ( adh_previd.Length == 0)) {
					FDCLogger.LogEvent("AdhConsultation a ete apeller sans argument adh.", source, 2);
				}
				else {
					js_previd_var = "var Adh = \"" + adh_previd + "\"";

					FDCLogger.LogEvent("AdherentConsultation a ete apeller avec argument adh " + adh_previd, source, 3);
					imgEdit.NavigateUrl = "AdherentEdition.aspx?adh=" + adh_previd;
					imgAdd.NavigateUrl = "AdherentAjout.aspx";
					LoadData(adh_previd);
				}
			}
		}



		private void LoadData(string adhid) {
			FDCLogger.LogEvent("La page est en train de charger les informations de la base de donne", source, 4);
			ConnectionManager cn = new ConnectionManager();
			SqlConnection conn = cn.GetSqlConnection();
			SqlCommand tsql = conn.CreateCommand();

			#region// ETAT CIVILE
			tsql.CommandType = CommandType.StoredProcedure;
			tsql.CommandText = "spGetETAT_CIVILE_byPrevID";
			SqlParameter param = tsql.Parameters.Add("@PREV_ID", SqlDbType.NVarChar);
			param.Value = adhid;
			conn.Open();

			using (SqlDataReader reader = tsql.ExecuteReader()) {
				while (reader.Read()) {
					if (reader.HasRows) {
						FDCLogger.LogEvent("La page est en train de charger les informations d'etat civile", source, 4);
						txtPREV_ID.Text = reader.GetValue(0).ToString();
						txtNOM.Text = reader.GetValue(1).ToString();
						txtPRENOM.Text = reader.GetValue(2).ToString();
						txtINTITULE.Text = reader.GetValue(3).ToString();
						txtSITUATION_FAM.Text = reader.GetValue(4).ToString();
						txtANNIV.Text = reader.GetValue(5).ToString();
					}
				}
			}
			conn.Close();
			#endregion
			#region// ADRESSE
			tsql.CommandText = "spGetADRESSE_byPrevID";
			conn.Open();

			using (SqlDataReader reader = tsql.ExecuteReader()) {
				while (reader.Read()) {
					if (reader.HasRows) {
						FDCLogger.LogEvent("La page est en train de charger les informations d'adresse", source, 4);
						txtAdr1.Text = reader.GetString(0);
						txtAdr2.Text = reader.GetString(1);
						txtCodePostal.Text = reader.GetString(2);
						txtVille.Text = reader.GetString(3);
					}
				}
			}
			conn.Close();
			#endregion
			#region// STATUS
			tsql.CommandText = "spGetSTATUS_byPrevID";
			conn.Open();
			using (SqlDataReader reader = tsql.ExecuteReader()) {
				while (reader.Read()) {
					if (reader.HasRows) {
						FDCLogger.LogEvent("La page est en train de charger les informations de status", source, 4);
						txtAD.Text = reader.GetString(0);
						txtSECTION.Text = reader.GetString(1);

						if (reader.GetString(2) == "OUI") {
							chkRETENU.Checked = true;
						}
						// txtRUB2.Text = reader.GetString(3);
						if (!reader.IsDBNull(4)) {
							txtIRET.Text = reader.GetString(4);
						}
						if (!reader.IsDBNull(5)) {
							txtOTIG.Text = reader.GetString(5);
						}
						txtADHESION.Text = reader.GetString(6);
						if (!reader.IsDBNull(7)) {
							txtAFFECTATION.Text = reader.GetString(7);
						}
					}
				}
			}
			conn.Close();
			#endregion
			#region//CONTACT

			tsql.CommandText = "spGetCONTACT_byPrevID";
			conn.Open();

			bool headerSet = false;

			using (SqlDataReader reader = tsql.ExecuteReader()) {
				while (reader.Read()) {
					if (reader.HasRows) {
						FDCLogger.LogEvent("La page est en train de charger les informations de contact", source, 4);

						if (!headerSet) {
							#region //SET TABLE HEADER
							TableRow head = new TableRow();
							head.Height = 30;
							//head.BackColor = Color.White;

							TableCell cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Ref# "));
							cell.Width = 70;
							head.Cells.Add(cell);

							cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Valeur"));
							cell.Width = 90;
							head.Cells.Add(cell);

							cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Type"));
							cell.Width = 90;
							head.Cells.Add(cell);

							cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Description"));
							cell.Width = 150;
							head.Cells.Add(cell);

							tblContact2.Rows.Add(head);
							#endregion
							headerSet = true;
						}

						TableRow r = new TableRow();
						r.Height = 30;

						for (int i = 0; i < 4; i++) {
							TableCell c = new TableCell();
							c.Controls.Add(new LiteralControl(reader.GetValue(i).ToString()));
							r.Cells.Add(c);
						}
						tblContact2.Rows.Add(r);
					}
				}
			}
			conn.Close();
			#endregion
			#region //FAMILLE
			tsql.CommandText = "spGetFAMILLE_byPrevID";
			conn.Open();

			headerSet = false;

			using (SqlDataReader reader = tsql.ExecuteReader()) {
				while (reader.Read()) {
					if (reader.HasRows) {
						FDCLogger.LogEvent("La page est en train de charger les informations de famille", source, 4);

						if (!headerSet) {
							#region //SET TABLE HEADER
							TableRow head = new TableRow();
							head.Height = 30;
							//head.BackColor = Color.White;

							TableCell cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Ref #"));
							cell.Width = 70;
							head.Cells.Add(cell);

							cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Position"));
							cell.Width = 70;
							head.Cells.Add(cell);

							cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Nom"));
							cell.Width = 80;
							head.Cells.Add(cell);

							cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Prenom"));
							cell.Width = 80;
							head.Cells.Add(cell);

							cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Sexe"));
							cell.Width = 70;
							head.Cells.Add(cell);

							cell = new TableCell();
							cell.Controls.Add(new LiteralControl("Anniv."));
							cell.Width = 90;
							head.Cells.Add(cell);

							tblFamille.Rows.Add(head);
							#endregion
							headerSet = true;
						}

						TableRow r = new TableRow();
						r.Height = 30;

						for (int i = 0; i < reader.FieldCount; i++) {
							TableCell c = new TableCell();
							c.Controls.Add(new LiteralControl(reader.GetValue(i).ToString()));
							c.Width = 70;
							r.Cells.Add(c);
						}
						tblFamille.Rows.Add(r);
					}
				}
			}
			#endregion
		}
	</script>
	<!-- The following section is added at run time by AdhConsultation.aspx.cs. This need to be changed. -->
	<script type="text/javascript" language="javascript"><%Response.Write(js_previd_var);%></script>
	<script src="/LAFDCWeb/FamilleEdition.aspx.js" type="text/javascript"></script>
</head>
<body onload="loadRoutage()">
    <form id="form1" runat="server">
        <div id="header">
        <table style="width: 100%; background-color:Transparent";>
            <tr style="height: 30px">
                <td style="width: 3%" align="center">
                <a href="./" target="_parent">
                    <img alt="Accueil" src="images/home_16x16.PNG" border="0" /></a>
                </td>
                <td style="width: 70%">
                    Fichier adh&eacute;rent: Consultation</td>
                <td style="width: 20%" align="right">
                    <asp:HyperLink ID="imgAdd" runat="server" ImageUrl="images/add.gif"/>
                    <asp:HyperLink ID="imgEdit" runat="server" ImageUrl="images/edit.gif"/>
                </td>
            </tr>
        </table>
        <hr />
    </div>
        <div>
            <table style="width: 814px;" cellspacing="0">
                <tr style="background-color: #ffffcc; height: 30px">
                    <td colspan="4" style="background-color: #ffffcc">
                        <b>ETAT CIVILE:</b></td>
                </tr>
                <tr style=" height: 30px">
                    <td style="width: 140px; height: 30px;">
                        Nom:</td>
                    <td colspan="1" style="width: 140px; height: 30px; ">
                        <asp:Label ID="txtNOM" runat="server" BackColor="Transparent" ></asp:Label></td>
                    <td style="width: 140px;">
                        Pr&eacute;nom:</td>
                    <td style="width: 140px; height: 30px; ">
                        <asp:Label ID="txtPRENOM" runat="server" BackColor="Transparent"></asp:Label></td>
                </tr>
                <tr style="background-color: white; height: 30px">
                    <td style="width: 230px;">
                        Intitul&eacute;:</td>
                    <td style="width: 230px;">
                        <asp:Label ID="txtINTITULE" runat="server" BackColor="Transparent"></asp:Label></td>
                    <td style="width: 230px;">
                        Sit. famille:</td>
                    <td style="width: 230px;">
                        <asp:Label ID="txtSITUATION_FAM" runat="server" BackColor="Transparent" ></asp:Label></td>
                </tr>
                <tr style="height: 30px">
                    <td style="width: 160px;">
                        Pr&eacute;voyances:</td>
                    <td style="width: 281px;">
                        <asp:Label ID="txtPREV_ID" runat="server" BackColor="Transparent" ></asp:Label></td>
                    <td style="width: 140px;">
                        Date de Naiss.</td>
                    <td style="width: 230px;">
                        <asp:Label ID="txtANNIV" runat="server" BackColor="Transparent"></asp:Label></td>
                </tr>
                <tr style="height: 30px">
                    <td colspan="4" style="height: 30px; background-color: #ffffcc;">
                        <b>ADRESSE:</b>
                    </td>
                </tr>
                <tr style="height: 30px">
                    <td style="width: 160px;">
                        Adresse:</td>
                    <td colspan="3">
                        <asp:Label ID="txtAdr1" runat="server" BackColor="Transparent"></asp:Label></td>
                </tr>
                <tr style="height: 30px">
                    <td style="width: 160px;">
                        Adresse:</td>
                    <td colspan="3" style="">
                        <asp:Label ID="txtAdr2" runat="server" BackColor="Transparent"></asp:Label></td>
                </tr>
                <tr style="height: 30px">
                    <td style="width: 160px">
                        Code postal:</td>
                    <td >
                        <asp:Label ID="txtCodePostal" runat="server" BackColor="Transparent"></asp:Label></td>
                    <td>
                        Ville:</td>
                    <td >
                        <asp:Label ID="txtVille" runat="server" BackColor="Transparent" ></asp:Label></td>
                </tr>
                <tr style="height: 30px">
                    <td colspan="4" style="height: 30px; background-color: #ffffcc">
                        <b>STATUS:</b></td>
                </tr>
                <tr style="height: 30px">
                    <td style="width: 160px">
                        AD:</td>
                    <td >
                        <asp:Label ID="txtAD" runat="server" BackColor="Transparent"></asp:Label></td>
                    <td>
                        Section:</td>
                    <td >
                        <asp:Label ID="txtSECTION" runat="server" BackColor="Transparent"></asp:Label></td>
                </tr>
                <tr style="height: 30px;">
                    <td style="width: 160px">
                        Adh&eacute;sion:</td>
                    <td style="width: 281px;">
                        <asp:Label ID="txtADHESION" runat="server"></asp:Label></td>
                    <td style="width: 140px;">
                        Retenu:</td>
                    <td style="width: 230px;">
                        <asp:CheckBox ID="chkRETENU" runat="server" Width="203px" /></td>
                </tr>
                <tr style="height: 30px">
                    <td style="width: 160px">
                        OTIG:</td>
                    <td >
                        <asp:Label ID="txtOTIG" runat="server" BackColor="Transparent"></asp:Label></td>
                    <td>
                        Ind. retraite:</td>
                    <td >
                        <asp:Label ID="txtIRET" runat="server" BackColor="Transparent"></asp:Label></td>
                </tr>
                <tr style="height: 30px">
                    <td style="width: 160px;">
                        Affectation:</td>
                    <td style="width: 281px;">
                        <asp:Label ID="txtAFFECTATION" runat="server" BackColor="Transparent"></asp:Label></td>
                    <td style="width: 140px">
                    Routage du journal:</td>
                <td style="width: 230px">
                    <input type="checkbox" id="chkROUTAGE" readonly="readonly"/></td>
                </tr>
                <tr style="height: 30px">
                    <td colspan="4" style="height: 30px; background-color: #ffffcc">
                        <strong>CONTACT:</strong>
                    </td>
                </tr>
                <tr style="height: 30px"><td></td>
                    <td colspan="3">
                        <asp:Table id="tblContact2" GridLines="Horizontal" CellPadding="5" 
                        CellSpacing="0" Runat="server" Width="95%" BorderStyle="Double"/>
                    </td>
                </tr>
                <tr style="height: 30px; background-color: #ffffcc">
                    <td colspan="3">
                        <strong style="height: 30px; background-color: #ffffcc">FAMILLE:</strong></td>
                        <td align="center">
                            <input onclick="open_win()" type="button" value="Edition Famille..." /></td>
                </tr>
                <tr style="height: 30px"><td></td>
                    <td colspan="3">
                        <asp:Table id="tblFamille" GridLines="Horizontal" CellPadding="5" 
                        CellSpacing="0" Runat="server" Width="95%" BorderStyle="None"/></td>
                </tr>
            </table>
        </div>
	</form>
	<script type="text/javascript" language="javascript">
		function open_win(){
			var path="/LAFDCWeb/FamilleEdition.aspx?adh=" + Adh
			window.open( path,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=700, height=370")
		}
		function close_win(){
			window.close()
		}
	</script>
</body>
</html>
